<?php
class AttachController extends AppController {
    var $helpers = array ('Html','Form');
    var $name = 'Attach'; // riferimento alla cartella delle view

    public function beforeFilter(){
    	
		parent::beforeFilter();

    	Controller::loadModel('Attach');

    }
    
    public function index() {

    }

    public function edit($id) {

    }

    public function upload() {

    	// print_r($this->request->data['attachTipo']);

    	try {
    		// per la gestione delle transazioni
			$dataSource = $this->Attach->getDataSource();
    		$dataSource->begin($this->Attach);
			
			$this->Attach->set('file_name', $_FILES["file"]["name"]);
			// $this->Attach->set('path', $this->request->data['path']);
			$this->Attach->set('attach_tipo', $this->request->data['attachTipo']);
			$utente = $this->Auth->user();
			$this->Attach->set('path', "/".$utente['id']);
			$this->Attach->set('ut_ins', $utente['id']);
			$this->Attach->set('dt_ins', date("y/m/d H:i:s"));
			
			// $this->Attach->set('dt_ins', $this->Auth->User);
			// $this->Attach->set('ut_ins', $this->Auth->User);
			$this->Attach->set('dimensione', $_FILES["file"]["size"]);
			$this->Attach->set('tipo', $_FILES["file"]["type"]);
			$this->Attach->setFileTemporaneo($_FILES["file"]["tmp_name"]);
			$this->Attach->save();
	
			$this->Session->setFlash('Attach salvato!');
			$dataSource->commit($this->Attach);

    	} catch (exception $e) {
			$this->Session->setFlash($e->getMessage());
    		$dataSource->rollback($this->Attach);
    	}

		$this->redirect("/Attach/index");
			
		
		
    }
	
    public function dowload() {

    }

    public function delete($id='') {
		
    }
	
	

}
?>